//
//  camera.cpp
//  RPG
//
//  Created by Matt Bailey on 30/12/2013.
//  Copyright (c) 2013 Matt Bailey. All rights reserved.
//

#include "camera.hpp"

void Camera::init() {
    
    refX = ((Map::getWidth() * Map::getTileWidth()) - Window::getWidth()) / 2;
    refY = ((Map::getHeight() * Map::getTileWidth()) - Window::getHeight()) / 2;
    
    cameraX = refX;
    cameraY = refY;
}

void Camera::translateCamera(int x, int y) {
    
    cameraX += x;
    cameraY += y;
    
}

void Camera::updateCamera() {
    
    float newViewPort_Width = (float)Window::getWidth() * zoom;
    float newViewPort_Height = (float)Window::getHeight() * zoom;
    
    Projection = glm::ortho((float)Window::getWidth() - newViewPort_Width, newViewPort_Width, newViewPort_Height, (float)Window::getHeight() - newViewPort_Height, -10.0f, 10.0f);
    View = glm::lookAt(glm::vec3(cameraX, cameraY, 1), glm::vec3(cameraX, cameraY, 0), glm::vec3(0, 1, 0));
    
    MVP = Projection * View * Model;
}

void Camera::setZoom(const float zoomLevel) {
    
    float maxZoom = 0.5f;
    zoom += zoomLevel / -100;
    
    if (zoom < maxZoom) {
        zoom = maxZoom;
    }
}

glm::mat4 Camera::Model = glm::mat4(1.0f);
glm::mat4 Camera::View;
glm::mat4 Camera::Projection;

glm::mat4 Camera::MVP;

float Camera::refX;
float Camera::refY;

float Camera::cameraX;
float Camera::cameraY;

float Camera::zoom = 1.0f;

